package entity;

import java.util.Arrays;

import enumeration.Action;

public class ActionPoint {

    private double left;
    private double right;
    private double up;
    private double down;

    public double getLeft() {
        return left;
    }

    public void setLeft(double left) {
        this.left = left;
    }

    public double getRight() {
        return right;
    }

    public void setRight(double right) {
        this.right = right;
    }

    public double getUp() {
        return up;
    }

    public void setUp(double up) {
        this.up = up;
    }

    public double getDown() {
        return down;
    }

    public void setDown(double down) {
        this.down = down;
    }

    public double max() {
        double[] array = new double[]{left, right, up, down};
        Arrays.sort(array);
        return array[3];
    }

    public Action rightAction() {
        ActionKV leftAction = new ActionKV(Action.LEFT, left);
        ActionKV rightAction = new ActionKV(Action.RIGHT, right);
        ActionKV upAction = new ActionKV(Action.UP, up);
        ActionKV downAction = new ActionKV(Action.DOWN, down);
        ActionKV one;
        ActionKV two;
        if (leftAction.getValue() > rightAction.getValue()) {
            one = leftAction;
        } else if (leftAction.getValue() == rightAction.getValue()) {
            if (Math.random() > 0.5) {
                one = leftAction;
            } else {
                one = rightAction;
            }
        } else {
            one = rightAction;
        }

        if (upAction.getValue() > downAction.getValue()) {
            two = upAction;
        } else if (upAction.getValue() == downAction.getValue()) {
            if (Math.random() > 0.5) {
                two = upAction;
            } else {
                two = downAction;
            }
        } else {
            two = downAction;
        }

        if (one.getValue() > two.getValue()) {
            return one.getAction();
        }
        else if (one.getValue() == two.getValue()) {
            if (Math.random() > 0.5) {
                return one.getAction();
            } else {
                return two.getAction();
            }
        }
        else {
            return two.getAction();
        }
    }
}
